let proxyed = new Map()
let depends = new Map()
function reactive(obj){
    if (proxyed.get(obj) != null) {
        return proxyed.get(obj)
    }

    if (!(obj instanceof Object)) {
        return obj
    }
    let proxy = new Proxy(obj,
        {
            get(target, p, receiver) {
                console.log('obj getter')
                console.log(receiver)
                return Reflect.get(target,p,receiver)
            },
            set(target, p, newValue, receiver) {
                console.log('obj setter')
                let dependsArray = depends.get(receiver);
                for (let i = 0; i < dependsArray.length; i++) {
                   if (dependsArray[i].value !== undefined) {
                        dependsArray[i].value = newValue
                    }
                }
                Reflect.set(target,p,newValue,receiver)
            }
        });
    proxyed.set(obj,proxy)
    proxyed.set(proxy,proxy)
    depends.set(proxy,[])
    return proxy
}
function ref(obj, option){
    let newObj = {
        value: obj
    }
    return reactive(newObj)
}
function toRef(obj, propName){
    if (proxyed.get(obj) == null) {
        return null
    }
    let newObj = ref(obj[propName]);
    depends.get(proxyed.get(obj)).push(newObj)
    return newObj
}

function toRefs(obj){

}
// let obj1 = reactive(
//     "123"
// )
//
// let obj2 = ref(
//     "123"
// )

let obj3 = reactive(
    {
        name: 'hello'
    }
)
let obj4 = toRef(obj3,'name')


obj3.name = "world"
console.log(obj4.value)